﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FSY.Components.DataProvider;
using FSY.API.CacheManager;
using FSY.API.Utilities;
using FSY.Globals;
namespace FSY.Components.Entities
{
    public class Fsy_PortalController
    {
        public static Fsy_Portal GetPortalByID;
        private static int InsertDeleteUpdate(Fsy_Portal portal, DataProviderAction action)
        {
            Fsy_Cache.RemoveCache(cacheAll);
            return Fsy_DataProvider.Instance.Portal_AddDeleteUpdate(portal, action);
        }
        public static int Insert(Fsy_Portal portal)
        {            
            return InsertDeleteUpdate(portal, DataProviderAction.Insert);
        }
        public static int Delete(Fsy_Portal portal)
        {
            return InsertDeleteUpdate(portal, DataProviderAction.Delete);
        }
        public static int Update(Fsy_Portal portal)
        {
            return InsertDeleteUpdate(portal, DataProviderAction.Update);
        }

        private static object objlock = new object();
        private static string cacheAll = "allPortal";
        public static List<Fsy_Portal> GetAllPortal()
        {
            List<Fsy_Portal> lsPortal = new List<Fsy_Portal>();
            lock (objlock)
            {
                lsPortal = (List<Fsy_Portal>)Fsy_Cache.GetCache(cacheAll);
                if (lsPortal == null)
                {
                    lsPortal = Fsy_DataProvider.Instance.Portal_GetListAll();
                    if (lsPortal != null)
                        Fsy_Cache.SetCache(cacheAll, lsPortal, Fsy_Config.SlidingExpiration());
                    return lsPortal;
                }
            }
            return lsPortal;
        }
        public static bool IsExist(int id)
        {
            GetPortalByID = Fsy_DataProvider.Instance.Portal_GetByID(id);
            if (GetPortalByID != null)
            {
                return true;
            }
            return false;
        }
    }
}
